// ----------------
// Project:
// ESA Elevator
// ----------------
//
// ----------------
// Group: 163
// 2358569: Pascal Klink
// 2649456: Lukas Kreh 
// ----------------
//
// Description:
// ----------------
// elevator user-interface
//
// Version History:
// ----------------
// 140116: set parameter FLOORS to 30
// 140116: set parameter FLOOR_BITS to 5

`timescale 1ns / 1ns

module user_interface
             #(parameter FLOORS           = 30,
                         FLOOR_BITS       =  5,
                         DISPLAY_SEGMENTS = 14)
                      
              (
               input wire               	    CLK,
               input wire                           RESET,
               
               // INPUTS FROM CTRL UNIT                                                     		
               input  wire [(FLOOR_BITS-1)      :0] CURRENT_FLOOR,           
               input  wire                          HALTED,
               // INPUTS FROM BUTTONS
               input  wire [(FLOORS-1)          :0] FLOOR_SELECT,               // REQUESTS FROM CABIN                                  
               input  wire                          CLOSE_DOOR,  
					input  wire                          OPEN_DOOR,			
               input  wire                          PASSENGER_ALARM,                   		
               input  wire [(FLOORS*2)-1        :0] FLOOR_REQUEST,              // REQUESTS FROM FLOORS
                                   
               output wire [(FLOORS-1)          :0] ENLIGHT_BUTTONS,            // ENLIGHT ELEVATOR BUTTONS
               output wire [(FLOORS*2)-1        :0] ENLIGHT_FLOOR_BUTTONS,      // ENLIGHT FLOOR REQUEST BUTTONS
               output wire [(DISPLAY_SEGMENTS-1):0] ENABLE_SEGMENT,             // SEGMENT DISPLAY
               // OUTPUTS FOR CTRL UNIT
               output wire [(FLOOR_BITS-1)      :0] NEXT_FLOOR,			// DETERMINE NEXT FLOOR
					output wire [(FLOOR_BITS-1)      :0] CURRENT_FLOOR_OUT);               

/* =============================INSERT CODE HERE======================================*/ 

	//Register used to store the floor select (since the input FLOOR_SELECT only has high when the button is pressed)
	wire[FLOORS - 1:0] 		selected_buttons;
	//Register used to store the requested floors (sames explanation as above)
	wire[(FLOORS*2) - 1:0]	request_out;
	
	//Generate 7-segment display outputs
	display_if #(.FLOOR_BITS(FLOOR_BITS), .DISPLAY_SEGMENTS(DISPLAY_SEGMENTS)) 
		floor_display(.CURRENT_FLOOR(CURRENT_FLOOR), .ENABLE_SEGMENT(ENABLE_SEGMENT));
		
	//Generate englight signals for floor select
	keyboard_if #(.FLOORS(FLOORS), . FLOOR_BITS(FLOOR_BITS))
		keyboard(.CLK(CLK), .RESET(RESET), .FLOOR_SELECT(FLOOR_SELECT), .CLOSE_DOOR_IN(CLOSE_DOOR), .OPEN_DOOR_IN(OPEN_DOOR), .PASSENGER_ALARM_IN(PASSENGER_ALARM),
					.CLEAR_FLOOR_BUTTON(CURRENT_FLOOR), .CLEAR_FLOOR_BUTTON_VALID(HALTED), .ENLIGHT_BUTTONS(ENLIGHT_BUTTONS), .SELECTED_FLOORS(selected_buttons));
	
	//Generate englight signals for floor request
	floor_request_if #(.FLOORS(FLOORS), . FLOOR_BITS(FLOOR_BITS))
		floor_request(.CLK(CLK), .RESET(RESET), .CURRENT_FLOOR(CURRENT_FLOOR), .HALTED(HALTED), .FLOOR_REQUEST_IN(FLOOR_REQUEST), .ENLIGHT_BUTTONS(ENLIGHT_FLOOR_BUTTONS),
						  .FLOOR_REQUEST_OUT(request_out));
						  
	//Determine next floor
	next_floor_ctrl #(.FLOORS(FLOORS), . FLOOR_BITS(FLOOR_BITS))
		next_floor(.CLK(CLK), .RESET(RESET), .HALTED(HALTED), .CURRENT_FLOOR(CURRENT_FLOOR), .FLOOR_REQUEST(request_out), .DESTINATIONS(selected_buttons),
					  .NEXT_FLOOR(NEXT_FLOOR));
		
		
	assign CURRENT_FLOOR_OUT = CURRENT_FLOOR;
	
	
	
	
	





/* ====================================================================================*/
  
endmodule
